﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace DataTokensDemo
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            Route blogArchiveRoute = new Route(
                    "archiveParam/{database}/{year}/{month}/{day}",
                    new MvcRouteHandler()
                    );

            blogArchiveRoute.Defaults = new RouteValueDictionary(
                                new
                                {
                                    controller = "Home",
                                    action = "IndexParam"
                                });

            blogArchiveRoute.Constraints = new RouteValueDictionary(
                    new
                    {
                        database = "sport|technology",
                        year = @"\d{2}|\d{4}",
                        month = @"\d{1,2}",
                        day = @"\d{1,2}"
                    });

            routes.Add(blogArchiveRoute);

            Route blogSportArchiveRoute = new Route(
                "archiveDT/sport/{year}/{month}/{day}",
                new MvcRouteHandler()
                );

            blogSportArchiveRoute.Defaults = new RouteValueDictionary(
                                new
                                {
                                    controller = "Home",
                                    action = "IndexDT"
                                });

            blogSportArchiveRoute.Constraints = new RouteValueDictionary(
                                new
                                {
                                    year = @"\d{2}|\d{4}",
                                    month = @"\d{1,2}",
                                    day = @"\d{1,2}"
                                });

            blogSportArchiveRoute.DataTokens = new RouteValueDictionary(
                                new
                                {
                                    database = "sportConnString"
                                });

            routes.Add(blogSportArchiveRoute);

            Route blogTechnologyArchiveRoute = new Route(
                "archiveDT/technology/{year}/{month}/{day}",
                new MvcRouteHandler()
                );

            blogTechnologyArchiveRoute.Defaults = new RouteValueDictionary(
                                new
                                {
                                    controller = "Home",
                                    action = "IndexDT"
                                });

            blogTechnologyArchiveRoute.Constraints = new RouteValueDictionary(
                                new
                                {
                                    year = @"\d{2}|\d{4}",
                                    month = @"\d{1,2}",
                                    day = @"\d{1,2}"
                                });

            blogTechnologyArchiveRoute.DataTokens = new RouteValueDictionary(
                                new
                                {
                                    database = "techConnString"
                                });

            routes.Add(blogTechnologyArchiveRoute);

            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );
        }

        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }
    }
}